package com.crecheng.shop.DAO;

import com.crecheng.shop.Manage.ItemSpecificManage;

import java.util.List;

public class ItemData extends BaseData{
    String name;
    String description;
    String remark;
    List<ItemSpecificData> sp;
    int allSale;
    float lessPrice;

    public void init(){
        sp= ItemSpecificManage.getByParent(id);
        if(sp.size()>0)
        {
            int sale=0;
            float price=sp.get(0).price;
            for (var child:sp){
                sale+=child.getSale();
                if(price>child.getPrice())
                    price= child.getPrice();
            }
            allSale=sale;
            lessPrice=price;
        }
    }

    public void set(String name, String description, String remark) {
        this.name = name;
        this.description = description;
        this.remark = remark;
    }

    public List<ItemSpecificData> getSp() {
        return sp;
    }

    public void setSp(List<ItemSpecificData> sp) {
        this.sp = sp;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getRemark() {
        return remark;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getAllSale() {
        return allSale;
    }

    public void setAllSale(int allSale) {
        this.allSale = allSale;
    }

    public float getLessPrice() {
        return lessPrice;
    }

    public void setLessPrice(float lessPrice) {
        this.lessPrice = lessPrice;
    }

    @Override
    public String toString() {
        return "ItemData{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", remark='" + remark + '\'' +
                '}';
    }
}
